package cn.practice.chat.controller;

import cn.practice.chat.base.BaseController;
import cn.practice.chat.lang.Result;
import cn.practice.chat.request.chat.ChatGroupRequest;
import cn.practice.chat.request.chat.ChatRequest;
import cn.practice.chat.response.chat.ChatListResponse;
import cn.practice.chat.response.user.LoginUser;
import cn.practice.chat.service.ChatListService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName 聊天列表
 * @Description:
 * @Author A-TAO
 * @Date 2022/11/1
 * @Version V1.0
 **/
@Slf4j
@RestController
@RequestMapping("/chat")
public class ChatListController extends BaseController {

    @Autowired
    private ChatListService chatListService;

    /**
     * @description 获取聊天人列表
     * @return {@link Result< List< ChatListResponse>>}
     **/
    @GetMapping("/list")
    public Result<List<ChatListResponse>> chatList(){
        LoginUser loginUser =  getUser();
        log.info("当前登录的用户信息：{}", loginUser);
        List<ChatListResponse> list = chatListService.chatList(loginUser);
        return Result.success(list);
    }

    /**
     * @description 添加聊天人
     * @param chatRequest
     * @return {@link Result}
     **/
    @PostMapping("/create")
    public Result createUserChat(@RequestBody ChatRequest chatRequest){

        LoginUser loginUser =  getUser();
        log.info("当前登录的用户信息：{}", loginUser);

        chatListService.createUserChat(chatRequest, loginUser);
        return Result.success();
    }


    /**
     * @description 创建聊天群
     * @param chatGroupRequest
     * @return {@link Result}
     **/
    @PostMapping("/createGroup")
    public Result<ChatListResponse> createChatGroup(@RequestBody ChatGroupRequest chatGroupRequest){
        LoginUser loginUser =  getUser();
        log.info("当前登录的用户信息：{}", loginUser);
        ChatListResponse response = chatListService.createChatGroup(chatGroupRequest, loginUser);
        return Result.success(response);
    }
}
